package com.wejoy.video.middle.station.data.vo;


import java.io.Serializable;

/**
 * action ajax封装json数据的对象
 *
 * @author admin
 */
public class RespJSON implements Serializable {

    private static final long serialVersionUID = -1793734311569686636L;

    /**
     * 结果代码
     */
    private Integer code;

    /**
     * 结果描述
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    /**
     * 不允许外部new对象
     */
    private RespJSON() {
    }

    /**
     * 取得返回JsonResult对象
     *
     * @param returnCode
     * @return
     */
    public static RespJSON returnCode(ReturnCode returnCode) {
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(returnCode.getCode());
        respJSON.setMessage(returnCode.getMsg());
        return respJSON;
    }

    /**
     * 返回成功的数据
     *
     * @return
     */
    public static RespJSON success() {
        ReturnCode returnCode = ReturnCode.CODE_OK;
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(returnCode.getCode());
        respJSON.setMessage(returnCode.getMsg());
        return respJSON;
    }

    /**
     * 返回成功的数据
     *
     * @param data
     * @return
     */
    public static RespJSON success(Object data) {
        ReturnCode returnCode = ReturnCode.CODE_OK;
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(returnCode.getCode());
        respJSON.setMessage(returnCode.getMsg());
        respJSON.setData(data);
        return respJSON;
    }

    /**
     * 返回自定义code以及message
     */
    public static RespJSON returnCustomCodeWithMessage(Integer code, String message) {
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(code);
        respJSON.setMessage(message);
        return respJSON;
    }

    /**
     * 取得返回JsonResult对象
     *
     * @param
     * @param data
     * @return
     */
    public static RespJSON returnCode(ReturnCode returnCode, Object data) {
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(returnCode.getCode());
        respJSON.setMessage(returnCode.getMsg());
        respJSON.setData(data);
        return respJSON;
    }

    /**
     * 取得返回JsonResult对象
     *
     * @param returnCode
     * @param msgData
     * @return 返回信息的动态数据
     */
    public static RespJSON returnCodeWithMessage(ReturnCode returnCode, Object... msgData) {
        RespJSON respJSON = new RespJSON();
        respJSON.setCode(returnCode.getCode());
        if (msgData != null && msgData.length > 0 && returnCode.getMsg() != null) {
            respJSON.setMessage(String.format(returnCode.getMsg(), msgData));
        } else {
            respJSON.setMessage(returnCode.getMsg());
        }
        return respJSON;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 获取 数据
     *
     * @return
     */
    public Object getData() {
        return data;
    }

    /**
     * 设置 数据
     *
     * @param data
     */
    public void setData(Object data) {
        this.data = data;
    }
}
